package com.wmada.toolkit.ffmpeg;

import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.io.FileNotFoundException;

/**
 * @author will.ma
 * @date 2020-11-3
 */
public class Source {

    private File file;

    private Source() {
    }

    private Source(File file) {
        this.file = file;
    }

    public File getFile() {
        return file;
    }

    public String getPath() {
        return file.getAbsolutePath();
    }

    @NotNull
    public static Source of(@NotNull String path) throws FileNotFoundException {
        File file = new File(path);
        if (!file.exists()) {
            throw new FileNotFoundException(path);
        }
        if (!file.isFile()) {
            throw new IllegalArgumentException(path + " is not file.");
        }
        return new Source(file);
    }

    @NotNull
    public static Source of(@NotNull File file) throws FileNotFoundException {
        if (!file.exists()) {
            throw new FileNotFoundException(file.getAbsolutePath());
        }
        if (!file.isFile()) {
            throw new IllegalArgumentException(file.getAbsolutePath() + " is not file.");
        }
        return new Source(file);
    }

}
